package com.example.warehouse.sys.dao.persist.respository.impl;

import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.util.PageInfoToPageDataConverter;
import com.example.warehouse.sys.dao.persist.mapper.NoticeMapper;
import com.example.warehouse.sys.dao.persist.respository.INoticeRepository;
import com.example.warehouse.sys.pojo.entity.SysNotice;
import com.example.warehouse.sys.pojo.vo.NoticeListItemVO;
import com.example.warehouse.sys.pojo.vo.NoticeSelectVO;
import com.example.warehouse.sys.pojo.vo.NoticeStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * @author 欧胤
 * @version 1.0
 * @description: TODO
 * @date 2023/7/6 17:48
 */

@Slf4j
@Repository
public class NoticeRepositoryImpl implements INoticeRepository {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public int insert(SysNotice sysNotice) {
        log.debug("开始向通知表中插入数据, 参数: {}",sysNotice);

        return noticeMapper.insert(sysNotice);
    }

    @Override
    public int deleteById(Long id) {
        return noticeMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Collection<Long> idList) {
        return noticeMapper.deleteBatchIds(idList);
    }

    @Override
    public int update(SysNotice sysNotice) {
        return noticeMapper.updateById(sysNotice);
    }

    @Override
    public int count() {
        return noticeMapper.selectCount(null);
    }

    @Override
    public NoticeStandardVO getStandardById(Long id) {
        return noticeMapper.getStandardById(id);
    }

    @Override
    public NoticeStandardVO getStandardByNotice(NoticeSelectVO notice) {
        return noticeMapper.getStandardByNotice(notice);
    }


    @Override
    public PageData<NoticeListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询文章列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<NoticeListItemVO> list = noticeMapper.list();
        PageInfo<NoticeListItemVO> pageInfo = new PageInfo<>(list);
        PageData<NoticeListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<NoticeListItemVO> listByNotice(NoticeSelectVO notice,Integer pageNum, Integer pageSize) {
        List<NoticeListItemVO> noticeListItemVOS = noticeMapper.listByNotice(notice);
        PageInfo<NoticeListItemVO> pageInfo = new PageInfo<>(noticeListItemVOS);
        PageData<NoticeListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }


}
